let { connection, requestApi } = require("../database/db.js")


exports.UserList = async (req, res) => {

    let { page = 1, size = 4 } = req.query
    let sql = `SELECT * FROM user1 LIMIT ${(page - 1) * size},${size}`
    // connection.query(sql, (err, data) => {
    //     if (err) {
    //         return res.json({
    //             status: 1001,
    //             msg: "查询失败",
    //             err: err
    //         })
    //     } else {
    //         res.json({
    //             status: 200,
    //             msg: "成功",
    //             data: data
    //         })
    //     }
    // })
    let countSql = `SELECT COUNT(*) FROM user1 WHERE is_show=1`
    let result = await requestApi(sql)
    let resultCount = await requestApi(countSql)
    // console.log(resultCount);
    let count = resultCount[0]['COUNT(*)'] //总的数据条数
    let pages = Math.ceil(count / size)
    res.json({
        status: 200,
        msg: "成功",
        page: page,
        size: size,
        pages: pages,
        data: result
    })
    // res.send("ok")
}